package com.titar.robot.ui.dialog;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.TextView;


import com.titar.robot.R;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class DialogActivity extends AppCompatActivity {
    
    public static void showDialog(Context context, String title, String content) {
//        Context appContext = context.getApplicationContext();
//        Intent intent = new Intent(context, DialogActivity.class);
//        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        intent.putExtra("title", title);
//        intent.putExtra("content", content);
//        appContext.startActivity(intent);
        showDialog(context, title, content, null);
    }


    public static void showDialog(Context context, String title, String content, Intent acitivtyIntnet) {
        Context appContext = context.getApplicationContext();
        Intent intent = new Intent(context, DialogActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("title", title);
        intent.putExtra("content", content);
        intent.putExtra("activity", acitivtyIntnet);
        appContext.startActivity(intent);

    }
    
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_dialog);
        TextView title = (TextView) findViewById(R.id.title);
        TextView content = (TextView) findViewById(R.id.content);
        
        Intent intent = getIntent();
        if(intent != null) {
            String titleStr = intent.getStringExtra("title");
            String contentStr = intent.getStringExtra("content");
            final Intent activityIntent = intent.getParcelableExtra("activity");

            title.setText(titleStr);
            content.setText(contentStr);

            if(activityIntent != null) {
                View view = getWindow().getDecorView();
                view.findViewById(android.R.id.content)
                        .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(activityIntent);
                        finish();
                    }
                });
            }
        }
    }
}